<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增banner信息')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-banner-add">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">名称：</label>
                <div class="col-sm-8">
                    <input name="bannerName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">图片地址：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="bannerImg" id="logo" required class="form-control">
                    <div class="fileinput fileinput-new" data-provides="fileinput">
<!--                        <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px;"></div>-->
                        <div>
                            <span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span><span class="fileinput-exists">更改</span>
                            <input name="file" id="file1" type="file" onchange="upload('file1')" accept="image/gif,image/jpg,image/jpeg,image/png"></span>
                            <a href="javascript:void(0)" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: ajax-upload-js"/>
    <th:block th:include="include :: jasny-bootstrap-js" />
    <script th:inline="javascript">
        var prefix = ctx + "cms/banner"
        $("#form-banner-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-banner-add').serialize());
            }
        }

        //租户banner图片上传
        function upload(fileId) {
            var file = document.getElementById(fileId);
            $.modal.loading("正在上传中，请稍后...");
            $.ajaxFileUpload({
                url: ctx + '/common/upload',
                secureuri: false,
                type: "text",
                fileElementId: fileId,
                dataType: 'multipart/form-data',
                success: function (data, status) {
                    console.info(data);
                    $.modal.closeLoading();
                    data = JSON.parse($(data).text());
                    $("#logo").val(data.url);
                    $.modal.msgSuccess("文件上传成功")
                },
                error: function (status, e) {
                    console.info(e);
                    $.modal.closeLoading();
                    $.modal.msgError("文件上传失败！");
                }
            });
        }
    </script>
</body>
</html>